package cn.xfdzx.android.apps.shop.adapter;

import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.FamilyBuyBeen;

public class HomeMarketFamilyAdapter extends BaseQuickAdapter<FamilyBuyBeen.DataBean.FamilyShoppingActivityBean, BaseViewHolder> {
    RoundedCorners roundedCorners;
    RequestOptions options;

    public HomeMarketFamilyAdapter() {
        super(R.layout.adapter_maarket_home_family);
        roundedCorners = new RoundedCorners(8);
        options = RequestOptions.bitmapTransform(roundedCorners).override(200, 200);
        options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
                .error(R.drawable.icon_defult);
    }


    @Override
    protected void convert(BaseViewHolder helper, FamilyBuyBeen.DataBean.FamilyShoppingActivityBean item) {
        Glide.with(mContext).load(item.getThumb()).apply(options.transform(new CenterCrop(), roundedCorners)).into((ImageView) helper.getView(R.id.iv_image));

        helper.setText(R.id.tv_home_name, item.getTitle())
                .setText(R.id.tv_new_price, "¥" + item.getDiscountprice())
                .setText(R.id.tv_old_price, "¥" + item.getMarketprice());

        TextView oldPrice = helper.getView(R.id.tv_old_price);
        oldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

        TextView tvCarNum = helper.getView(R.id.tv_car_num);
        tvCarNum.setText(item.getCart_num() + "");
        if (item.getCart_num() == 0) {
            tvCarNum.setVisibility(View.GONE);
        } else {
            tvCarNum.setVisibility(View.VISIBLE);
        }

        helper.addOnClickListener(R.id.iv_add_car);
    }
}
